import axios from 'axios'

const baseURL = import.meta.env.VITE_APP_BASE_URL

const instance = axios.create({
  baseURL,
  timeout: 5000,
  method: 'POST'
})

instance.interceptors.request.use(
  (config) => {
    const _config = { ...config }

    if (!_config.url.includes('login')) {
      _config.headers.authorization = localStorage.getItem('token')
    }
    return _config
  },
  (err) => Promise.reject(err)
)

instance.interceptors.response.use((res) => {
  console.log(res)
  return res.data
}, undefined)

export default instance
